package com.yztc.yidoutang.http.zhuye;

import com.yztc.yidoutang.bean.GoodsListBean;
import com.yztc.yidoutang.bean.ZhuYeBean;
import com.yztc.yidoutang.http.HttpHelper;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 主页页面中处理网络数据的DAO类
 */
public class ZhuYeDao {
    /**
     * 获取商品列表的回调方法，调用这个方法并重写subscriber中的方法即可完成回调
     *
     * @param subscriber 网络请求的异步处理对象
     */
    public static void getZhuYeData(Subscriber<ZhuYeBean> subscriber) {
        getRetrofitService()
                .getZhuYeData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public static void getGoodsList(Subscriber<GoodsListBean> subscriber, String order, String space) {
        getRetrofitService()
                .getGoodsList(order, space, "0")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    /**
     * 获取Service对象
     */
    private static ZhuYeService getRetrofitService() {
        return HttpHelper.getInstance().getRetrofit().create(ZhuYeService.class);
    }
}